$(function(){
	var isSmallScreen=false,menuLeft=$('.pub-menu-left');
	function setSize(){
		var w=document.documentElement.clientWidth,h=document.documentElement.clientHeight;
		menuLeft.height(h)
		$('.pub-iframe').height(h-70);
		setTimeout(function () {
            $('.pub-header .name').css({left:$('.pub-menu-left').width()+20});
        },200);
		if(w>1400){
			isSmallScreen=false;
			$('body').removeClass('small-screen');
			$('.pub-iframe').width(w-menuLeft.width()-3-20).css({marginLeft:20});
			showMenu();
		}else{
			isSmallScreen=true;
			$('body').addClass('small-screen');
			hideMenu();
			$('.pub-iframe').width(w-80).css({marginLeft:80});
		}
	}
	setSize();
	window.onresize=setSize;
	
	/*window.onfocus=function(){
		$('iframe')[0].contentWindow.location.reload();
	}*/
	
	/*点击左侧菜单*/
	var fors,navson=menuLeft.find('.nav-son'),currentNavson=null;
	menuLeft.find('.li').click(function(){
		menuLeft.find('.li').removeClass('on');
		navson.stop().slideUp(300);
		currentNavson=$(this).find('nav');
		currentNavson.stop().slideDown(300);
		$(this).addClass('on');
		if($(this).find('nav').length!=0){
			$(this).find('nav a')[0].click();
		}
	});

	/*小屏幕时，左侧菜单左侧鼠标悬浮效果*/
	menuLeft.hover(showMenu,hideMenu);

	function showMenu(){
		//if(!isSmallScreen)return;
		clearTimeout(fors);
		var self=menuLeft;
		$(this).addClass('hover');
		fors=setTimeout(function(){
			if(currentNavson)currentNavson.show();
			self.find('.menu-name').css('display','inline');
		},200);
	}

	function hideMenu(){
		clearTimeout(fors);
		if(isSmallScreen){
			if(currentNavson)currentNavson.hide();
			menuLeft.removeClass('hover').find('.menu-name').hide();
		}
	}


	/*点击左侧二级菜单*/
	navson.find('a').click(function(event){
		event.stopPropagation();
		navson.find('a').removeClass('on');
		$(this).addClass('on');
		//sessionStorage.setItem('navson',$(this).index());
	});


	var recordUrl=sessionStorage.getItem('url');
	if(recordUrl){
		$('.pub-iframe').attr('src',recordUrl);
		var obj=$('.ul .li').removeClass('on').eq(sessionStorage.getItem('on')).addClass('on');
		if(!isSmallScreen){
			obj.find('.nav-son').show();
		}
		//if(sessionStorage.getItem('navson'))navson.find('a').eq(sessionStorage.getItem('navson')).addClass('on');
	}
	$('.pub-iframe')[0].onload=function(){
		$('.ul .li').each(function(i){
			if($(this).hasClass('on'))sessionStorage.setItem('on',i);
		});
		var url=this.contentWindow.location.href;
		sessionStorage.setItem('url',url);
	}
});
